package com.power.sifa.std.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.std.model.Std_matter_attach;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 申请所需材料 持久层(hibernate)
 */

public interface Std_matter_attachDao extends JpaRepository<Std_matter_attach, Serializable>, JpaSpecificationExecutor<Std_matter_attach>, Repository<Std_matter_attach, Serializable>, Std_matter_attachDaoCustom<Std_matter_attach, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Std_matter_attach s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   /**
    * 根据事项id获取申请材料列表定义
    * @param matid   事项id
    * @return
    */
   @Query(value = "select b.id, b.matid, b.attachid, b.sortnum, b.require, b.maxnum, b.filedown, b.filemake, b.fileverify, a.name, a.type, a.describe, a.tplfile attachtpl, b.tplfile mattertpl, b.maxfilesize from std_attach a join std_matter_attach b on a.id = b.attachid where b.matid = :matid order by b.sortnum", nativeQuery = true)
   List<Map<String, Object>> queryListByMatid(String matid);
}
